#ifndef _HARDWARE_H_
#define _HARDWARE_H_

#include <ctype.h>
#include <stdlib.h>

typedef ssize_t (*READ_FUNC_PTR)(void * handle, char * bfr, size_t n);
typedef ssize_t (*WRITE_FUNC_PTR)(void * handle, char * bfr, size_t n);
typedef void * (*OPEN_FUNC_PTR)(void * handle, int mode, int flag);
typedef int (*CLOSE_FUNC_PTR)(void * handle);
typedef int (*IOCTL_FUNC_PTR)(void * handle, int mode, void * arg);

typedef struct {
    link_node node;
    READ_FUNC_PTR read;
    WRITE_FUNC_PTR write;
    OPEN_FUNC_PTR open;
    CLOSE_FUNC_PTR close;
    IOCTL_FUNC_PTR ioctl;
    void * userData;
    int flags;
    void * handle;
    char devname[16];
    int lock;
} dev_inst;

typedef struct {
    link_node node;
    int handle;
    dev_inst * dev;
    void * userData;
} handle_inst;

dev_inst * hw_dev_add(dev_inst * dev);

handle_inst * findhandle(int handle);

#endif _HARDWARE_H_ /* end of _HARDWARE_H_ */

